package com.akk.module.yb.model;

import com.akk.PayConstants;
import com.akk.module.yb.utils.Digest;
import org.apache.commons.httpclient.methods.multipart.Part;
import org.apache.commons.httpclient.methods.multipart.StringPart;

import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;

/**
 * 信息查询请求
 */
public class YbQueryInfoRequest {
    private String mainCustomerNumber; // 代理商商户编号
    private String mobilePhone; //手机号
    private String customerNumber; //商户编号
    private String customerType; //商户类型
    private String hmac; //签名信息

    public String getMainCustomerNumber() {
        return mainCustomerNumber;
    }

    public void setMainCustomerNumber(String mainCustomerNumber) {
        this.mainCustomerNumber = mainCustomerNumber;
    }

    public String getMobilePhone() {
        return mobilePhone;
    }

    public void setMobilePhone(String mobilePhone) {
        this.mobilePhone = mobilePhone;
    }

    public String getCustomerNumber() {
        return customerNumber;
    }

    public void setCustomerNumber(String customerNumber) {
        this.customerNumber = customerNumber;
    }

    public String getCustomerType() {
        return customerType;
    }

    public void setCustomerType(String customerType) {
        this.customerType = customerType;
    }

    public String getHmac() {
        return hmac;
    }

    public void setHmac(String hmac) {
        this.hmac = hmac;
    }

    public static String signature(YbQueryInfoRequest request) {
        StringBuffer sb = new StringBuffer();
        sb.append(request.getMainCustomerNumber() == null?"":request.getMainCustomerNumber());
        sb.append(request.getMobilePhone()== null ?"":request.getMobilePhone());
        sb.append(request.getCustomerNumber() == null?"":request.getCustomerNumber());
        sb.append(request.getCustomerType() == null?"":request.getCustomerType());
        System.out.println(sb.toString());
        System.out.println(Digest.hmacSign(sb.toString(), PayConstants.YB_PARAMS_HMAC_KEY));
        return Digest.hmacSign(sb.toString(), PayConstants.YB_PARAMS_HMAC_KEY);
    }

    public static Part[] builderPart(YbQueryInfoRequest request) {
        List<Part> parts = new ArrayList<Part>();
        parts.add(new StringPart("mainCustomerNumber",request.getMainCustomerNumber()==null?"":request.getMainCustomerNumber(),"UTF-8"));
        parts.add(new StringPart("mobilePhone",request.getMobilePhone() == null ? "":request.getMobilePhone(),"UTF-8"));
        parts.add(new StringPart("hmac",request.getHmac() == null ?"":request.getHmac(),"UTF-8"));
        parts.add(new StringPart("customerNumber",request.getCustomerNumber()==null?"":request.getCustomerNumber(),"UTF-8"));
        parts.add(new StringPart("customerType",request.getCustomerType() == null?"":request.getCustomerType(),"UTF-8"));
        return parts.toArray(new Part[parts.size()]);
    }


}
